﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
	public partial class wfPopularCity : msBsc.Cls.BPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

        private void getArea2(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string cityId = this.GetParamHtValue("cityId");
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""cityId_select""," + ret + @",""" + cityId + @""")");
            }
        }

        private void getPopularCity()
        {
            string parentsId = this.GetParamHtValue("cityId");
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.GetTopCity(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    this.ExecJScript(@"$('#travel_list').html('');");
                    return;
                }
                string cityId = this.GetParamHtValue("cityId");
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@" var _html = $('#city_list_temp').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                                $('#travel_list').html(render);
                            });");
            }
        }

        public override void DoAction()
        {
            if (this.strAction=="init")
            {
                string parentsId = this.GetParamHtValue("parentsId");
                getArea2(parentsId);
                getPopularCity();
            }
            else if (this.strAction=="upCity")
            {
                getPopularCity();
            }
        }

	}
}